#include "timer.h"
#include "time_module.h"
//#include "performance.h"

namespace common
{

	ITimer::ITimer() : list_link_(this)
	{
		active_time_ = 0;
	}

	ITimer::ITimer(const ITimer& rhs) : list_link_(this)
	{
		active_time_ = rhs.active_time_;
	}

	ITimer::~ITimer()
	{
		RealStop();
	}

	int ITimer::RealStart()
	{
		return	CTimeModule::GetInstance().RegisterTimer(*this);
	}

	int ITimer::RealStop()
	{
		return CTimeModule::GetInstance().UnregisterTimer(*this);
	}

	CTimer::CTimer()
	{
		delta_time_ = 0;
	}

	CTimer::~CTimer()
	{
	}

	int32_t CTimer::TimerInit(int64_t delta_time)
	{
		if (delta_time <= 0)
		{
			return ERR_INVAILD_PARAM;
		}
		delta_time_ = delta_time;
		return SUCCEED;
	}

	int32_t CTimer::TimerStop()
	{
		return RealStop();
	}

	int32_t CTimer::TimerStart()
	{
		active_time_ = CTimeModule::GetInstance().cur_ms() + delta_time_;
		return RealStart();
	}

	void CTimer::Active()
	{
		//PERF_ALIVE( TimeActive );
		TimerActive();
	}


}//namespace common
